package indi.gao.sort;

import com.alibaba.fastjson.JSONObject;
import indi.gao.model.Apple;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author :gaolei
 * @version :v1.0
 * @projectName :sprintboot
 * @description :
 * @createDate :2021/8/10 6:13 下午
 */
public class SortTest {
    @Test
    public void getSortReturn() {
        Apple gao = Apple.builder().name("gao").build();
        Apple wang = Apple.builder().name("wang").build();
        Apple li = Apple.builder().name("li").build();
        ArrayList<Apple> apples = new ArrayList<>();
        apples.add(gao);
        apples.add(wang);
        apples.add(li);

        apples.sort(Comparator.comparingInt(x -> x.getName().hashCode()));
        System.out.println(JSONObject.toJSONString(apples));
    }
}
